package com.example.openim.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.openim.enums.ErrorCode;
import com.example.openim.service.TYRZUserService;
import com.example.openim.utils.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

/**
 * @description: 获取统一认证用户信息
 * @author: xhq
 * @create: 2025-11-05 16:35
 */
@RestController
@RequestMapping("/api/lf")
@Slf4j
public class TYRZUserInfoController {

    @Autowired
    private TYRZUserService tyrzUserService;

    /**
     * 获取用户信息
     *
     * @return
     */
    @PostMapping("/queryUserInfo")
    public AjaxResult queryUserInfo(@RequestBody Map<String, String> requestBody) {
        String code = requestBody.get("code");
        if (StringUtils.isEmpty(code)) {
            return AjaxResult.error(ErrorCode.ERROR.getCode(), "参数不能为空");
        }
        JSONObject jsonObject = this.tyrzUserService.queryUserInfo(code);
        if (Objects.isNull(jsonObject)) {
            return AjaxResult.error(ErrorCode.ERROR.getCode(), "未查到有效用户");
        }

        return new AjaxResult(jsonObject);
    }
}
